package br.great.DAO;

import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
* PhotoMap
* Copyright (c) 2007-2008 STEAMER - LIG, All rights reserved.
*/

/**
 * @author Developpement of PhotoMap
 */
public class DAO_ContentAnnotationHasTag {

    int i;
       private PreparedStatement insertStatement;
    private static volatile DAO_ContentAnnotationHasTag instaceDAO_ContentAnnotationHasTag = new DAO_ContentAnnotationHasTag();
    
    /** The private constructor of DAO_ContentAnnotationHasTag for singleton
    */
    private DAO_ContentAnnotationHasTag(){
     try {
            PgConnect conn = PgConnect.getInstance();
            insertStatement = conn.executeInsertWithPreparedStatement(getInsertStatement());
        } catch (Exception ex) {
            System.err.println("Problems to prepare statement");
        }
    }
    public String getInsertStatement(){
        String insertTuple= "insert into Content_Annotation_Has_Tag values(?,?,?);";
        return  insertTuple; 
    }
    
    /** The method for get the instance of the class DAO_ContentAnnotationHasTag
    * @return DAO_ContentAnnotationHasTag instaceDAO_ContentAnnotationHasTag
    */
    public static DAO_ContentAnnotationHasTag getInstance() {
        //if(instaceDAO_ContentAnnotationHasTag==null)
           synchronized(DAO_ContentAnnotationHasTag.class) {
             if (instaceDAO_ContentAnnotationHasTag == null)
               instaceDAO_ContentAnnotationHasTag = new DAO_ContentAnnotationHasTag();
           }
        return instaceDAO_ContentAnnotationHasTag;
    }
    
    public void insertContentAnnotationHasTag(int idTag, int idContentAnnotation, double weight){
        try {
              insertStatement.setInt(1, idContentAnnotation);
              insertStatement.setInt(2, idTag);
              insertStatement.setDouble(3,weight);
              insertStatement.execute();        
             /*
            String insertContentAnnotationHasTag = "insert into Content_Annotation_Has_Tag values("+idContentAnnotation+","+idTag+","+weight+");";
            
            PgConnect conn = PgConnect.getInstance();
            conn.executeInsert(insertContentAnnotationHasTag);
            conn.Close();
            */
        } catch (Exception ex) {
         //   System.err.println ("Error insert Content Anotation has Tag");
        }
    }
    
//    public static void main(String[] args){
//        DAO_ContentAnnotationHasTag dchca = DAO_ContentAnnotationHasTag.getInstance();
//        dchca.insertContentAnnotationHasTag(3, 26);
//    }

}
